class DbViewHeavenVotes < ActiveRecord::Migration
  def self.up
    # Creo la vista con il numero di voti del purgatorio per ogni persona. Da http://osdir.com/ml/RubyonRailsTalk/2009-07/msg02521.html
    execute( "create view conta_voti_paradiso(name, surname, voti_paradiso) as
              select people.name, people.surname, count(*) as voti_paradiso
              from vote_tracks join people on vote_tracks.person_id = people.id
              where vote_tracks.vote_type='heaven'
              group by vote_tracks.person_id")
  end

  def self.down
    execute( "DROP VIEW 'conta_voti_paradiso'")
  end
end